<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: relative;
            margin: 100px auto;
            width: 344px;
            border-bottom: 1px solid red;
        }
        
        div input {
            width: 300px;
            height: 24px;
            border: 0;
            outline: none;
        }
        
        div img {
            position: absolute;
            top: 2px;
            right: 7px;
            width: 24px;
        }
    </style>
</head>

<body>
    <div>
        <input type="password">
        <img src="images\close.png" alt="">
    </div>
    <script>
        var input = document.querySelector('input');
        var img = document.querySelector('img');
        var flag = 0;
        img.onclick = function() {
            if (flag == 0) {
                input.type = "text";
                img.src = "images/open.png";
                flag = 1;
            } else {
                input.type = "password";
                img.src = "images/close.png";
                flag = 0;
            }
        }
    </script>
</body>

</html>